package com.nc.delivery_project.server.service;

import com.nc.delivery_project.server.dao.PermissionDao;
import com.nc.delivery_project.server.db_util.ConnectionManager;
import com.nc.delivery_project.server.util.CRUD;
import com.nc.delivery_project.server.domain.Permission;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by miroshnik on 12/28/2014.
 */
public class PermissionService implements CRUD<Permission> {

    @Override
    public Permission read(int id) {
        Permission perm = null;
        try {
            perm = new PermissionDao(ConnectionManager.getInstance().getConnection()).read(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return perm;
    }

    @Override
    public List<Permission> read() {
        List<Permission> perms = null;
        try {
            perms = new PermissionDao(ConnectionManager.getInstance().getConnection()).read();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return perms;
    }

    @Override
    public int create(Permission obj) {
        try {
            new PermissionDao(ConnectionManager.getInstance().getConnection()).create(obj);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return 1;
    }

    @Override
    public void delete(int id) {
        try {
            new PermissionDao(ConnectionManager.getInstance().getConnection()).delete(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void update(Permission obj) {
        try {
            new PermissionDao(ConnectionManager.getInstance().getConnection()).update(obj);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
